package com.vickw.springcloud;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;

/**
 * @version 1.0
 * @Description：
 * @Author VickW
 * @Date 2022/3/18 23:42
 */
@SpringBootApplication
@Slf4j
@EnableCircuitBreaker  //启动服务降级的注解
@EnableEurekaClient
public class HystrixPaymentMain8001 {
    public static void main(String[] args) {
        log.info("***************HystrixPaymentMain8001服务开始启动***************");
        SpringApplication.run(HystrixPaymentMain8001.class,args);
        log.info("***************HystrixPaymentMain8001服务启动成功***************");
    }

    @Bean // 注入豪猪的servlet
    // 此配置是为了服务监控而配置，与服务容错本身无关，springcloud升级后的一个坑
    // springboot默认路径不是/hustrix.stream，只要在自己的项目里自己配置servlet
    public ServletRegistrationBean getServlet(){
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(streamServlet);
        servletRegistrationBean.setLoadOnStartup(1);
        servletRegistrationBean.addUrlMappings("/hystrix.stream");
        servletRegistrationBean.setName("HystrixMetricsStreamServlet");
        return servletRegistrationBean;
    }

}
